package com.totoro.dubbo.providerservice.service.impl;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.totoro.dubbo.provider.service.IHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * Created by Niki on 2018/6/29 17:44
 */
@Service
public class HelloServiceImpl implements IHelloService {

    @Autowired
    ApplicationConfig applicationConfig;
    @Autowired
    RegistryConfig registryConfig;
    @Autowired
    ProtocolConfig protocolConfig;

    @Override
    public String sayHello() {
        System.out.println("Hello Dubbo!");
        return "Hello World!";
    }

    @PostConstruct
    public void registry() {
        ServiceConfig<IHelloService> service = new ServiceConfig<>();
        service.setApplication(applicationConfig);
        service.setRegistry(registryConfig);
        service.setProtocol(protocolConfig);

        service.setInterface(IHelloService.class);
        service.setRef(this);
        service.setVersion("1.0.0");
        service.export();
    }
}
